#!/usr/bin/perl

if ($#ARGV != 0) {
	usage();
}

my $arg = shift @ARGV;
if ($arg ne "w2u" and $arg ne "u2w") {
	usage();
}

my $from = ($arg eq "w2u") ? "(\015\012?|\012)" : "\n";
my $to   = ($arg eq "u2w") ? "\015\012" : "\n";

my $srcdir = ($arg eq "w2u") ? "bin" : "unix";
my $dstdir = ($arg eq "w2up") ? "unix" : "bin";

my @files = ("AYLAR.dta", "AYLAR.prs", "HOTELS.dta", 
             "BILLREC.dta", "GRAND.dta", "GRAND.prs");

for my $file ( @files ) {
    open FILE, "$srcdir/$file" or next;
    my @lines = <FILE>;
    close FILE;

    foreach my $i ( 0..$#lines ) {
        $lines[$i] =~ s/$from/$to/g;
    }

    open FILE,">","$dstdir/$file";
    print FILE @lines;
    close FILE;	

    print "Copied $srcdir/$file to $dstdir/$file\n";
}



sub usage {
	print("Usage:\n\tcpwin u2w\n");
	print("\t\tCopy the unix files to the windows directory.\n\n");
	print("\tcpwin w2u\n");
	print("\t\tCopy the windows files to the unix directory.\n\n");
	die;
}
